package agenda.client;

import java.util.Arrays;
import java.util.List;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.view.client.ListDataProvider;

public class ContatosList extends Composite {
	private static class Contact {
	    private final String address;
	    private final String name;

	    public Contact(String name, String address) {
	      this.name = name;
	      this.address = address;
	    }
	  }

	  // The list of data to display.
	  private static List<Contact> CONTACTS = Arrays.asList(new Contact("John",
	      "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact(
	      "Zander", "94 Road Street"));
	
	public ContatosList() {
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		initWidget(absolutePanel);
		absolutePanel.setSize("542px", "315px");

		
		CellTable table = new CellTable<Contact>();
		
		absolutePanel.add(table);

	    // Create name column.
	    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
	      @Override
	      public String getValue(Contact contact) {
	        return contact.name;
	      }
	    };

	    // Make the name column sortable.
	    nameColumn.setSortable(true);

	    // Create address column.
	    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
	      @Override
	      public String getValue(Contact contact) {
	        return contact.address;
	      }
	    };

	    // Add the columns.
	    table.addColumn(nameColumn, "Name");
	    table.addColumn(addressColumn, "Address");

	    // Create a data provider.
	    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

	    // Connect the table to the data provider.
	    dataProvider.addDataDisplay(table);

	    // Add the data to the data provider, which automatically pushes it to the
	    // widget.
	    List<Contact> list = dataProvider.getList();
	    for (Contact contact : CONTACTS) {
	      list.add(contact);
	    }

	    // Add it to the root panel.
	    //RootPanel.get().add(table);		
		
		
	}
}
